package com.loong.life.business;

import com.loong.common.mybatis.business.AbstractBusiness;
import com.loong.life.common.backend.param.AgentProductQueryParam;
import com.loong.life.model.AgentProduct;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @Description:
 * @Author: 刘群
 * @Date: 2020/11/26 16:31
 */
@Repository
public class AgentProductBusiness extends AbstractBusiness<AgentProduct> {

    /**
     * 根据参数查询代理商产品
     * @param param 查询参数
     * @return 代理商产品集合
     */
    public List<AgentProduct> findAgentProductByParam(AgentProductQueryParam param){
        Condition condition = new Condition(AgentProduct.class);
        Example.Criteria criteria = condition.createCriteria();
        if (ObjectUtils.isNotEmpty(param.getAgentId())){
            //代理商id
            criteria.andEqualTo("agentId",param.getAgentId());
        }
        if (ObjectUtils.isNotEmpty(param.getProductCode())){
            //产品名称
            criteria.andLike("productCode","%"+param.getProductCode()+"%");
        }
        if (ObjectUtils.isNotEmpty(param.getProductType())){
            //产品类型
            criteria.andEqualTo("productType",param.getProductType());
        }
        if (ObjectUtils.isNotEmpty(param.getStatus())){
            //状态
            criteria.andEqualTo("status",param.getStatus());
        }
        return findByCondition(condition);
    }
}
